package org.hgvc.webapp.ets.jsf.beans.admin;

import java.util.Date;
import java.util.List;

import org.hgvc.webapp.ets.bo.Agent;
import org.hgvc.webapp.ets.bo.AgentCommission;
import org.hgvc.webapp.ets.constant.AgentConstant;
import org.hgvc.webapp.ets.spring.service.AgentService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;



public class AdminAgentCommBean extends AbstractBean {

	private AgentService service;
	private Agent agent;
	private Date to;
	private Date from;
	private List<AgentCommission> commissionList;
	public static final String BEAN_NAME="adminAgentCommBean";
	public static final String NAV_ACC_ACTION="adminAgentCommAcc";
	public static final String NAV_NON_ACC_ACTION="adminAgentCommNacc";
	
	public Date getTo() {
		return to;
	}
	public void setTo(Date to) {
		this.to = to;
	}
	public Date getFrom() {
		return from;
	}
	public void setFrom(Date from) {
		this.from = from;
	}
	
	public void setService(AgentService service) {
		this.service = service;
	}
	
	/*------------------------------------------------------------*
	 * 
	 */
	public String navListAction(Agent agent){
		this.agent = agent;
		if(agent.getSchema().getAccumulateType().equalsIgnoreCase(AgentConstant.AGENT_COMM_SCH_ACC_TYPE_ACC)){
			return NAV_ACC_ACTION.concat("_"+getRoleName());
		}else{
			return NAV_NON_ACC_ACTION.concat("_"+getRoleName());
		}
	}
	
	public String searchAction(){
		if(agent.getSchema().getAccumulateType().equalsIgnoreCase(AgentConstant.AGENT_COMM_SCH_ACC_TYPE_ACC)){
			return NAV_ACC_ACTION.concat("_"+getRoleName());
		}else{
			return NAV_NON_ACC_ACTION.concat("_"+getRoleName());
		}
	}
	
	public List<AgentCommission> getCommissionList() {
		try{
			commissionList = service.getAgentCommissionListByDateRange(agent.getAgentId(), from, to);
		}catch(BaseException be){
			be.printStackTrace();
			initErrorBean(be);
		}
		return commissionList;
	}
	
	public String backAction(){
		return AdminAgentMgmtBean.NAV_LIST_ACTION.concat("_"+getRoleName());
	}
}
